<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            margin: 0;
        }
        .box {
            margin: 100px auto;
            width: 800px;
            height: 200px;
            display: flex;
        }
        .box>.img {
            width: 300px;
            height: 100%;
        }
        .box>.img>img {
            width: 100%;
            height: 100%;
        }
        .box>.txt {
            flex: 1;
            height: 100%;
            border-top: 1px solid #e0e0e0;
            border-right: 1px solid #e0e0e0;
            border-bottom: 1px solid #e0e0e0;
            display: flex;
            flex-direction: column;
            justify-content: space-around;
            padding-left: 16px;
            box-sizing: border-box;
        }
        .txt>.one {
            font-size: 24px;
        }
        .txt>.two>span {
            /* width: 100px; */
            height: 30px;
            padding: 0 8px;
            line-height: 30px;
            text-align: center;
            display: inline-block;
            background-color: #e0e0e0;
            border-radius: 15px;
        }
        .txt>.th {
            display: flex;
            justify-content: space-between;
            padding-right: 16px;
            box-sizing: border-box;
        }
    </style>
</head>
<body>
    <!-- <div class="box">
        <div class="img">
            <img src="./img/u=1819248061,230866778&fm=193&f=GIF.jpg" alt="">
        </div>
        <div class="txt">
            <div class="one">5G商用在即，三大运营商营收持续下降</div>
            <div></div>
            <div class="two">
                <span>三大运营商</span>
                <span>中国移动</span>
                <span>5G商用</span>
            </div>
            <div class="th">
                <span>新京报经济新闻 2019-10-28 11:50:28</span>
                <span>评论数:58</span>
            </div>
        </div>
    </div> -->


    <script src="../lib/moment.min.js"></script>
    <script src="../lib/jquery.min.js"></script>
    <script>

        console.log(moment)
        const url = 'http://www.liulongbin.top:3006/api/news';
        const img1 = 'http://www.liulongbin.top:3006';
        // Promise
        // es6
        fetch(url, {
            method: 'get',
        })
        .then((res) => res.json())
        .then((res) => {
            console.log(res.data);

            for (const item of res.data) {
                const el = $(`
                    <div class="box">
                        <div class="img">
                            <img src="${img1 + item.img}" alt="">
                        </div>
                        <div class="txt">
                            <div class="one">${item.title}</div>
                            <div></div>
                            <div class="two">
                                ${
                                    item.tags.split(',')
                                    .map(tag => `<span>${tag}</span>`)
                                    .join(' ')
                                }
                            </div>
                            <div class="th">
                                <span>${item.source} ${moment(item.time).format('YYYY-MM-DD HH:mm:ss')}</span>
                                <span>评论数:${item.cmtcount}</span>
                            </div>
                        </div>
                    </div>
                `);
                el.appendTo($('body'));
            }
        });

    </script>
</body>
</html>